import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ToolTipItem } from "../../../../com/mui/manager/ToolTipItem";
import { ResFileConst } from "../../resource/ResFileConst";
import { CampChangeData } from "./CampChangeData";
import { ClockManager } from "../../manager/ClockManager";
import { Global } from "../../../../com/gengine/global/Global";
import { MsgManager } from "../../manager/MsgManager";
import { Cache } from "../../cache/Cache";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class CampChangePanel
    
    export  class CampChangePanel /* flash.display.Sprite */
    {
        constructor(arg1: int)
        {
            
            this.init(arg1);
            this._camp = arg1;
            addEventListener(flash.events.MouseEvent.ROLL_OVER, this.onMouseRollOverHandler);
            addEventListener(flash.events.MouseEvent.ROLL_OUT, this.onMouseRollOutHandler);
            return;
        }

        /* internal  */init(arg1: int): void
        {
            var loc2=null;
            var loc5=null;
            var loc6=null;
            this._bgNormal = ObjCreate.createBg(0, 0, 190, 365, this);
            this._bgLight = ObjCreate.createBg(-3, -2, 196, 369, this, ImagesConst.WindowSelectedBg);
            this._bgLight.visible = false;
            var loc1=ObjCreate.createBg(7, 7, 175, 150, this, ImagesConst.equipment_boarder);
            loc2 = new Object /* flash.display.Bitmap */();
            loc2.x = 16;
            loc2.y = 16;
            addChild(loc2);
            LoaderHelp.setBitmapdata("campImg_" + arg1 + ".swf", loc2);
            var loc3=ObjCreate.createBitmap("camp_" + arg1, 20, 115, this);
            var loc4=ObjCreate.createTextField("", 7, 162, 100, 20, this, GlobalStyle.textFormat6);
            (loc5 = ObjCreate.createTextField("", 7, 180, 174, 120, this)).wordWrap = true;
            loc5.multiline = true;
            var loc9=arg1;
            switch (loc9) 
            {
                case 1:
                {
                    loc4.text = Language.getString(36034);
                    loc5.htmlText = Language.getString(36035);
                    break;
                }
                case 2:
                {
                    loc4.text = Language.getString(36036);
                    loc5.htmlText = Language.getString(36037);
                    break;
                }
                case 3:
                {
                    loc4.text = Language.getString(36038);
                    loc5.htmlText = Language.getString(36039);
                    break;
                }
            }
            loc6 = new GTextFormat(FontUtil.EmbedNumberName, 18, 16580352);
            var loc7=new Object /* flash.display.Bitmap */();
            addChild(loc7);
            LoaderHelp.setBitmapdata("CampMark.swf", loc7);
            var loc8;
            (loc8 = new ToolTipItem()).x = 7;
            loc8.y = 280;
            addChild(loc8);
            loc8.addChild(loc7);
            loc8.toolTipData = Language.getString(36052);
            this._civilizationTxt = ObjCreate.createTextField("", 103, -2, 100, 25, loc8, loc6);
            this._civilizationTxt.embedFonts = true;
            this._campChangeBtn = ObjCreate.createGLoadedButton(ResFileConst.CampChange, 25, 292, 150, 48, this);
            this._campBtnTooltipItem = new ToolTipItem();
            this._campBtnTooltipItem.graphics.beginFill(16777215, 0.01);
            this._campBtnTooltipItem.graphics.drawRect(0, 0, 150, 48);
            this._campBtnTooltipItem.graphics.endFill();
            this._campBtnTooltipItem.visible = false;
            this._campBtnTooltipItem.cacheAsBitmap = true;
            this._campBtnTooltipItem.toolTipData = Language.getString(36047);
            ObjCreate.setObjAttri(this._campBtnTooltipItem, 25, 292, -1, -1, this);
            this._campChangeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCampChangeBtnHandler);
            this._restNumTxt = ObjCreate.createTextField("", 20, 340, 160, 20, this, new GTextFormat("", 12, 16777113, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._restNumTxt.filters = [];
            return;
        }

        /* internal  */onMouseRollOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._bgLight.visible = true;
            return;
        }

        /* internal  */onMouseRollOutHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._bgLight.visible = false;
            return;
        }

        /* internal  */onCampChangeBtnHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=null;
            if (!(CampChangeData.civilizationInfo.topCamp == this._camp) || CampChangeData.isActived && CampChangeData.isInActived) 
            {
                loc1 = ClockManager.instance.nowDate;
                loc2 = CampChangeData.civilizationInfo.openDt;
                if (loc1.time < loc2.time && !Global.isDebugModle) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(36040));
                    return;
                }
                if (Cache.instance.role.entityInfo.camp == this._camp) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(36041));
                    return;
                }
                if (Cache.instance.role.entityInfo.level < 45) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(36042));
                    return;
                }
                if (Cache.instance.guild.myGuildInfo) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(36043));
                    return;
                }
                if (CampChangeData.cdDays > 0) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(36044));
                    return;
                }
                if (Cache.instance.role.money.gold < 188) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(36045));
                    Alert.show(Language.getString(30103), null, Alert.OK | Alert.CANCEL, null, this.onPayClickHandler);
                    return;
                }
                Alert.show(Language.getString(36046), null, Alert.OK | Alert.CANCEL, null, this.onToChangeClickHandler);
            }
            return;
        }

        /* internal  */onPayClickHandler(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GotoPay));
            }
            Alert.resetToDefault();
            return;
        }

        /* internal  */onToChangeClickHandler(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CampToChange, this._camp));
            }
            Alert.resetToDefault();
            return;
        }

        public updateInfo(): void
        {
            this._campChangeBtn.styleName = ResFileConst.CampChange;
            this._campChangeBtn.enabled = true;
            this._campChangeBtn.toolTipData = "";
            this._campBtnTooltipItem.visible = false;
            if (CampChangeData.civilizationInfo) 
            {
                if (CampChangeData.civilizationInfo.topCamp == this._camp && !CampChangeData.isActived && !CampChangeData.isInActived) 
                {
                    this._campChangeBtn.enabled = false;
                    this._campBtnTooltipItem.visible = true;
                }
                if (CampChangeData.civilizationInfo.civilizations) 
                {
                    if (CampChangeData.civilizationInfo.civilizations[this._camp] == null) 
                    {
                        CampChangeData.civilizationInfo.civilizations[this._camp] = 0;
                    }
                    this._civilizationTxt.text = CampChangeData.civilizationInfo.civilizations[this._camp] + "";
                }
            }
            this.updateRestNum();
            return;
        }

        public updateRestNum(): void
        {
            if (CampChangeData.civilizationInfo && !CampChangeData.isActived && !CampChangeData.isInActived) 
            {
                if (!(CampChangeData.civilizationInfo.topCamp == this._camp) && CampChangeData.campNumChanged) 
                {
                    this._restNumTxt.text = Language.getString(36048) + CampChangeData.campNumChanged[this._camp];
                }
                else 
                {
                    this._restNumTxt.text = Language.getString(36049);
                }
            }
            return;
        }

        /* internal */ /* var */_bgNormal: ScaleBitmap;

        /* internal */ /* var */_bgLight: ScaleBitmap;

        /* internal */ /* var */_camp: int;

        /* internal */ /* var */_campChangeBtn: GLoadedButton;

        /* internal */ /* var */_campBtnTooltipItem: ToolTipItem;

        /* internal */ /* var */_civilizationTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_restNumTxt: Object /* flash.text.TextField */;
    }
